home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / HARDWARE.SWG / 0042_Determine CPU Type.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  3KB  |  78 lines

  1. {
  2. Here is the code I use, adapted from the Intel Pentium Processor User's
  3. Manual, Chapter 5.  It sets the Test8086 global variable, making the values
  4. of Test8086:
  5.  
  6.  
  7.    0 = 8086
  8.    1 = 80186/80286
  9.    2 = 80386
  10.    3 = 80386   (new)
  11.    4 = 80486   (new)
  12.    5 = Pentium (new)
  13.    6 = ??
  14.  
  15.  
  16. Note that for Pentium and higher CPUs, the new CPUID instruction is used to
  17. retrieve the processor family number.  This code should work on post-Pentium
  18. (80686-class) CPUs and Pentium compatibles, and could return numbers > 5.
  19. }
  20.  
  21.  program CPUTest;
  22.  {$IFDEF WINDOWS}
  23.  uses wincrt;
  24.  {$ELSE}
  25.  uses crt;
  26.  {$ENDIF}
  27.  
  28.  begin
  29.   if (Test8086 = 2) then         { RTL check stops at 2 = 386}
  30.   asm
  31.              inc    Test8086     { 3 = 386, for consistency }
  32.     { Do we have a 386 or a 486? }
  33.     { Does pushf/popf preserve the Alignment Check bit? (386=no, 486=yes) }
  34.              mov    bx, sp       { save current stack pointer }
  35.              and    sp, not 3    { align stack to avoid AC fault }
  36.     db $66;  pushf
  37.     db $66;  pop    ax
  38.     db $66;  mov    cx, ax
  39.     db $66, $35; dd $40000       { xor AC bit in EFLAGS }
  40.     db $66;  push   ax
  41.     db $66;  popf
  42.     db $66;  pushf
  43.     db $66;  pop    ax
  44.     db $66;  xor    ax, cx       { Is AC bit toggled? }
  45.              je @@1              { if not, we have a 386 }
  46.              and    sp, not 3    { align stack to avoid AC fault }
  47.     db $66;  push   cx
  48.     db $66;  popf                { restore original AC bit }
  49.              mov    sp, bx       { restore original stack pointer }
  50.              mov  Test8086, 4    { we know we have at least a 486 }
  51.  
  52.     { Do we have a 486 or a Pentium? }
  53.     { Does pushf/popf preserve the CPUID bit? (486=no, P5=yes) }
  54.     db $66;  mov    ax, cx       { get original EFLAGS}
  55.     db $66, $35; dd $200000      { XOR id bit in flags}
  56.     db $66;  push   ax
  57.     db $66;  popf
  58.     db $66;  pushf
  59.     db $66;  pop    ax
  60.     db $66;  xor    ax, cx      { Is CPUID bit toggled? }
  61.              je @@1             { if not, we have a 486 }
  62.     db $66;  xor    ax, ax
  63.     db $f,$a2                   { CPUID, AX = 0 (get CPUID caps) }
  64.     db $66;  cmp    ax, 1
  65.              jl @@1             { if < 1, then exit }
  66.     db $66;  xor    ax, ax
  67.     db $66;  inc    ax
  68.     db $f,$a2                   { CPUID, AX = 1 (get CPU info)   }
  69.              and    ax, $f00    { mask out all but family id }
  70.              shr    ax, 8
  71.              mov    Test8086, al      { Pentium family = 5 }
  72.    @@1:
  73.   end;
  74.  
  75.   writeln('Test8086: ',Test8086);
  76.  end.
  77.  
  78.